package com.example.result.explore

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Button
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch


@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class)
@Composable
fun ExploreScreen() {
    Box(modifier = Modifier.padding(16.dp)) {
        val pageTitles = arrayOf(
            "打印触摸指针", "JNI调用", "按钮样式", "卡片样式",
            "芯片样式", "对话框样式", "进度条样式", "文本样式",
            "文本编辑样式", "滑块样式", "开关样式", "底部动作条",
            "抽屉式导航栏", "快捷信息栏", "网格布局", "粘性标题列表",
            "粘性标题横向列表", "组件颜色对照", "Messenger使用",
            "Effects探索"
        )

        val pagerState = rememberPagerState(0, 0f) { pageTitles.size }
        HorizontalPager(
            modifier = Modifier.fillMaxHeight(),
            state = pagerState
        ) { pageId ->
            when (pageId) {
                0 -> PrintPointerInputEvent()
                1 -> JNIExpose()

                2 -> ButtonShow()

                3 -> CardShow()

                4 -> ChipShow()

                5 -> DialogShow()

                6 -> ProgressShow()
                7 -> TextShow()
                8 -> TextFiedShow()
                9 -> SliderShow()
                10 -> SwitchShow()
                11 -> ModalBottomSheetShow()
                12 -> DrawerShow()
                13 -> SnackBarShow()
                14 -> LazyVerticalGridShow()
                15 -> ColumShow()
                16 -> RowShow()
                17 -> ColorShow()
                18 -> ProcessCommunication()
                19 -> EffectsExpose()
            }
        }
        Text(
            text = "currentPageOffsetFraction:${pagerState.currentPageOffsetFraction}\n:currentPage:${pagerState.currentPage}\nsettledPage:${pagerState.settledPage}",
            modifier = Modifier
                .align(Alignment.BottomStart)
                .alpha(0.7f)
        )
        var showSelectPage by remember {
            mutableStateOf(false)
        }
        Button(onClick = {
            showSelectPage = true
        }, modifier = Modifier.align(Alignment.BottomEnd)) {
            Text(text = pageTitles[pagerState.currentPage])
        }
        val coroutine = rememberCoroutineScope()
        DropdownMenu(expanded = showSelectPage, onDismissRequest = {
            showSelectPage = false
        }) {
            pageTitles.forEachIndexed { i, it ->
                DropdownMenuItem(
                    onClick = {
                        showSelectPage = false
                        coroutine.launch {
                            pagerState.animateScrollToPage(i)
                        }
                    },
                    text = { Text(text = it) }
                )
            }
        }

        FlowRow(
            Modifier
                .wrapContentHeight()
                .fillMaxWidth()
                .align(Alignment.BottomCenter)
                .padding(bottom = 8.dp)
                .alpha(0.7f),
            horizontalArrangement = Arrangement.Center
        ) {
            repeat(pagerState.pageCount) { iteration ->
                val color =
                    if (pagerState.currentPage == iteration) Color.DarkGray else Color.LightGray
                Box(
                    modifier = Modifier
                        .padding(2.dp)
                        .clip(CircleShape)
                        .background(color)
                        .size(16.dp)
                )
            }
        }
    }
}



